var vm = new Vue({
    el: "section",
    data: {
        //header add
        search_value: "",
        showAction: false,
        userid: "",
        showResult: false
    },
    methods: {
        // 搜索框
        onSearch() {
            // 检查输入内容
            // 输入为空
            if(/^\s*$/.test(this.search_value)){
                this.$toast({
                    message: '请输入内容！',
                    forbidClick: true
                });
                this.search_value = ""
                return
            }
            let toast1 = this.$toast.loading({
                message: '加载中...',
                forbidClick: true,
                loadingType: 'circular',
                duration: 10000
              });
            let url = `https://fc-mp-e8e2bde5-0c0c-4622-87b5-66f8b08c3856.next.bspapp.com/getArticleList1.0`
            let method = `searchUser_V89178bf4nh81KR4U81`
            let data = {
                userid: this.userid,
                userID: this.search_value
            }
            axios.post(`${url}/${method}`, data)
            .then(res=>{
                toast1.clear()
                if(res.data.code === 0){
                    if(res.data.data.length == 0){
                        this.showResult = true
                    }else{
                        if(res.data.data[0].code == -1){
                            this.$toast({
                                message: '不能添加自己到通讯录',
                                forbidClick: true
                            })
                        }else if(res.data.data[0].code == 0){
                            let href = `../detail_user/index.html?userID=${this.search_value}`
                            window.location.href = href
                        }
                        
                    }

                }else{
                    this.$toast({
                        message: `服务出错[${res.data.code}]`,
                        forbidClick: true
                    })
                }
                
            })  
        },
        onFocus() {
            this.showAction = true;
            this.showResult = false
        },
        onCancel() {
            this.showAction = false;
            this.showResult = false
        },
    },
    mounted(){
        let userInfo = localStorage.getItem('XGB-user')
        this.userid = JSON.parse(userInfo).id
    }
})